package com.dragon.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 操作状态枚举
 *
 * @author dragon
 * @version 1.0
 * @date 2024/8/5 14:07
 */
@Getter
public enum BusinessStatus {

    /**
     * 失败
     */
    FAIL(0, "失败"),

    /**
     * 成功
     */
    SUCCESS(1, "成功"),
    ;

    /**
     * 操作状态
     */
    private final Integer code;

    /**
     * 操作状态描述
     */
    private final String des;

    BusinessStatus(Integer code, String des) {
        this.code = code;
        this.des = des;
    }

    public static BusinessStatus getByCode(Integer code) {
        return Arrays.stream(values()).filter(item -> item.code.equals(code)).findFirst().orElse(null);
    }

    public static String getDesByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }

        BusinessStatus businessStatus = getByCode(code);
        return Objects.isNull(businessStatus) ? null : businessStatus.getDes();
    }

}
